package com.cmccgz.udacs_landlord_webapp.main.housemanager.list;

import android.content.Intent;
import android.os.Bundle;

import com.cmccgz.baselibrary.base.BaseActivity;
import com.cmccgz.udacs_landlord_webapp.R;
import com.cmccgz.udacs_landlord_webapp.data.Injection;

/**
 * @author: Huang
 * @Descripion:
 * @date 2017/6/5 09:09
 */

public class HouseListActivity extends BaseActivity {

    public static final int TYPE_NULL = 0;//无类型
    public static final int TYPE_RENT_ROOM = 1;//租房
    public static final int TYPE_CHECKOUT = 2;//退房
    public static final int TYPE_EXCHANGE = 3;//换房
    public static final int TYPE_ROOM_COUNT = 4;//房间统计
    public static final int TYPE_SELECT_BUILDING = 5;//选择楼栋
    public static final int TYPE_SELECT_HOUSE = 6;//选择房间
    public static final String TYPE = "type";
    public static final String IS_FOR_SELECTED = "isForSelected";
    public static final int RESULT_CODE = 0x888;
    public static final int FINISH_CODE = 0x444;
    public static final String HOUSE_NAME = "house_name";
    public static final String HOUSE_ID = "house_id";
    private int type;
    private boolean isForSelected;

    @Override
    protected int setLayoutId() {
        return 0;
    }

    @Override
    protected void initView() {
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        type = intent.getIntExtra(TYPE, TYPE_NULL);
        isForSelected = intent.getBooleanExtra(IS_FOR_SELECTED,false);
    }

    @Override
    protected void initFragment() {
        HouseListFragment listFragment = (HouseListFragment) fragmentManager.findFragmentById(R.id.contentFrame);
        if (listFragment == null){
            listFragment = HouseListFragment.newInstance();
            Bundle bundle = new Bundle();
            bundle.putInt(TYPE,type);
            bundle.putBoolean(IS_FOR_SELECTED,isForSelected);
            listFragment.setArguments(bundle);
            showFragment(listFragment);
        }
        new HouseListPresenter(Injection.provideHouseManagerRepository(),listFragment);
    }

    @Override
    protected void beforePermission() {

    }

    @Override
    protected int setSystemBarColorId() {
        return 0;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == FINISH_CODE&&resultCode == RESULT_OK){
            finish();
        }
    }
}
